<?php
/**
 * Description of class_XML
 * 
 * PHP Class that reads a XML document. 
 *
 * @author Guillermo
 */
class XML {

    private $path ;
    private $doc;
  
    /**
     * Constructor of the class XML, it initialize the atributes path and doc. 
     * $path is the path of doc, and doc represents a DOMDocument/XML file.
     * @param type $paTh
     */
   public function XML($paTh){
       $this->path = $paTh;
       $doc = new DOMDocument();
       $doc->load($paTh);
       $this->doc = $doc;
   }
    /**
     * Method that returns a vector with all elements in a XML document.
     * 
     * @return type vector $elements
     */
    public function obtainElements(){
        $root = $this->doc->documentElement;
        $node = $root->firstChild;
            while ($node) {
                if (($node->nodeType == XML_ELEMENT_NODE) ) {
                         $elements[] = $node->nodeName;
                }
                $node = $node->nextSibling;
             }
        return $elements;
    }

   /**
    * Method that has got a parameter, it is a child node of an element. So,
    * it returns the value inside the node.
    * For instance: <node> my example value </node>
    *  it returns "my example value" 
    * 
    * @param type $nodeChild
    * @return type 
    */
  public function obtainData($nodeChild){
     $root = $this->doc->documentElement;
     $node = $root->firstChild;
     while ($node) {
        if (($node->nodeType == XML_ELEMENT_NODE) &&
        ($node->nodeName == $nodeChild)) {
            $content = $node->firstChild;
            $output = $content->nodeValue;
            return $output;
        break;
           }
     $node = $node->nextSibling;
    }
  }
}

?>
